import { Component } from 'react';

import { Toast, Button, Group} from 'saltui';
import DB from '../../../app/db';
import './PageHome.less';
import SelectMember from 'components/selectMember';

export default class PageHome extends Component {


 constructor(props) {
    super(props);

    //关闭加载页的遮罩效果
    $(".loading-containter").hide();
    
    let id = this.props.params.id;
    var thirdMenuType = getLoginUserInfo().thirdMenuType;
    let memoUser = this.props.params.memoUser;
    this.state = {
      meetingId:id,
      memoUser: memoUser ? memoUser : "",
      jsonStrMemoUser:'',
      thirdMenuType:thirdMenuType,
    };

    
    if(thirdMenuType == 'DING'){
      dd.biz.navigation.setTitle({
          title : "变更记录人",//控制标题文本，空字符串表示显示默认文本
          onSuccess : function(result) {},
          onFail : function(err) {}
      });
    }else if(thirdMenuType =='MH'){
      !!emp&&emp.window.setTitle({
          title: {
              text: "变更记录人",
              icon: '',
              actionmenu: {}
          },
      });
    }
  }

  componentDidMount(){
    this.refs.selectMember_change_memoUser.initSelectData();
  }
  
  submit(){
    let t = this;
    let jsonStrMemoUser = this.state.jsonStrMemoUser;
    if (jsonStrMemoUser=="" || jsonStrMemoUser==null || jsonStrMemoUser==undefined || jsonStrMemoUser.length==0) {
      Toast.show({
        type: 'error',
        content: '请选择记录人',
        onHide: function () {
        }
      });
      return;
    }else{
      jsonStrMemoUser = JSON.stringify(jsonStrMemoUser);
    }
    let param = {
      applyRecordId:this.state.meetingId,
      jsonStrMemoUser: jsonStrMemoUser
    }

    DB.SomeModuleAPI.changMemoUser(param).then((content) => {
      //返回至列表页面
      setTimeout(function(){
        t.cancel();
      },1500);
      Toast.show({
        type: 'success',
        content: content,
      });
    }).catch((error) => {
      if(typeof(error.errorMsg) == 'undefined'){
        Toast.show({
          type: 'error',
          content: '提交出错'
        });
      }else{
        Toast.show({
          type: 'error',
          content: error.errorMsg
        });
      }
    });
  }

  cancel(){
    history.back();
  }

  //获取联系人
  changeSelectMember(field, newValue){
      this.setState({
        [field]: newValue
      });
  }

  render() {
    let t = this;
    return (
      <div>
        <div>
          <Group.List>
            <SelectMember
              required={true}
              readOnly={false}
              label="记录人"
              placeholder="请选择"
              code="user"
              checkType="radio"
              isDelete={true}
              scopeTable="oa_meeting_apply_record_scope"
              fieldTable="oa_meeting_apply_record"
              fieldData="memo_user"
              ref="selectMember_change_memoUser"
              fieldDataValue={this.state.memoUser}
              showType="list"
              onChange={this.changeSelectMember.bind(this,"jsonStrMemoUser")}
            />
          </Group.List>
        </div>
        <div >
            <Button.Group >
                <Button type="primary" display="inline" onClick={this.submit.bind(this)}>确定</Button>
                <Button type="secondary" display="inline" onClick={this.cancel.bind(this)}>取消</Button>             
            </Button.Group>
        </div>
      </div>
    );
  }
}


